package com.foreknow.demo4;

import java.util.Scanner;

/**
 * 用自定义方法实现冒泡排序
 */

public class TestMethod8 {

    public static int[] popStart(int[] array) {
        for (int i = 1;i<array.length;i++) {
            for (int j = 0; j < array.length - 1; j++) { //相邻的两个元素进行比较
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                }
            }
        }
        return array;
    }

    public static void main(String[] args) {
        int[] arr ={15,7,22,14,8,16,10};
        int[] array = TestMethod8.popStart(arr);
        for (int i = 0;i<arr.length;i++) {
            System.out.println(arr[i]);
        }
    }
}







